/**
 * Project:   dtu.fmes.googleloon
 * File:      GenerateWinds.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright:	Nicolai Sonne [ NicolaiSonne@hotmail.com.com ]
 * Date:      Dec 11, 2013
 */

package dtu.fmes.loon;

import java.util.Locale;
import java.util.Random;

/**
 * Standalone class used for generating wind matrix. Output should be
 * copy-pasted to GenerateData.java
 * 
 * @author Nicolai Sonne
 * 
 */
public class GenerateWinds {

	private static Random rand = null;

	// Wind speeds constraints
	private static Double minWind = 10.0;
	private static Double maxWind = 20.0;

	// Wind angle variance in degrees
	private static Double windVariance = 15.0;

	// Winds in "X" direction
	private static int windXAmount = 8;
	// Total winds in each layer. Must be multiple of windXAmount!
	private static int windLayerAmount = 16;

	public static void main(String[] args) {
		// Initialize random generator
		rand = new Random(Double.doubleToLongBits(Math.random()));

		// Start array
		System.out.println("{");

		// Start layer
		System.out.println("\t{");

		// First layer
		for (int i = 0; i < windLayerAmount; i++) {
			isStart(i);
			printWind(1, rand.nextDouble() * windVariance + (90 - windVariance / 2));
			isEnd(i);
		}

		// Shift to next layer
		System.out.println("\t},");
		System.out.println("\t{");

		// Second layer
		for (int i = 0; i < windLayerAmount; i++) {
			isStart(i);
			printWind(2, rand.nextDouble() * windVariance + (270 - windVariance / 2));
			isEnd(i);
		}

		// Shift to next layer
		System.out.println("\t},");
		System.out.println("\t{");

		// Third layer
		for (int i = 0; i < windLayerAmount; i++) {
			isStart(i);
			printWind(3, rand.nextDouble() * windVariance + (0 - windVariance / 2));
			isEnd(i);
		}

		// Shift to next layer
		System.out.println("\t},");
		System.out.println("\t{");

		// Fourth layer
		for (int i = 0; i < windLayerAmount; i++) {
			isStart(i);
			printWind(4, rand.nextDouble() * windVariance + (180 - windVariance / 2));
			isEnd(i);
		}

		// End layer
		System.out.println("\t}");

		// End array
		System.out.println("};");
	}

	/**
	 * Start of new row in wind layer? Print accordingly
	 * 
	 * @param i
	 */
	private static void isStart(int i) {
		if ((i) % windXAmount == 0) {
			System.out.print("\t\t{ ");
		}
	}

	/**
	 * Generate random magnitude and print wind in Java format
	 * 
	 * @param height
	 * @param angle
	 */
	private static void printWind(int height, double angle) {
		Double magnitude = rand.nextDouble() * (maxWind - minWind) + minWind;
		System.out.print(String.format(Locale.ENGLISH, "new ImportWind(height%d, %.2f, %.2f)", height, magnitude, angle));
	}

	/**
	 * End of row? Print accordingly
	 * 
	 * @param i
	 */
	private static void isEnd(int i) {
		if ((i + 1) % windXAmount == 0) {
			if (i != windLayerAmount - 1) {
				System.out.println("},");
			} else {
				System.out.println("}");
			}
		} else {
			System.out.print(", ");
		}
	}
}
